from django.conf import settings
from django.urls import re_path

from dojo.engagement import views as dojo_engagement_views
from dojo.product import views
from dojo.utils import redirect_view

# TODO: remove the else: branch once v3 migration is complete
if settings.ENABLE_V3_ORGANIZATION_ASSET_RELABEL:
    urlpatterns = [
        re_path(
            r"^asset$",
            views.product,
            name="product",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)$",
            views.view_product,
            name="view_product",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/components$",
            views.view_product_components,
            name="view_product_components",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/engagements$",
            views.view_engagements,
            name="view_engagements",
        ),
        re_path(
            r"^asset/(?P<product_id>\d+)/import_scan_results$",
            dojo_engagement_views.ImportScanResultsView.as_view(),
            name="import_scan_results_prod",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/metrics$",
            views.view_product_metrics,
            name="view_product_metrics",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/async_burndown_metrics$",
            views.async_burndown_metrics,
            name="async_burndown_metrics",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/edit$",
            views.edit_product,
            name="edit_product",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/delete$",
            views.delete_product,
            name="delete_product",
        ),
        re_path(
            r"^asset/add",
            views.new_product,
            name="new_product",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/new_engagement$",
            views.new_eng_for_app,
            name="new_eng_for_prod",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/new_technology$",
            views.new_tech_for_prod,
            name="new_tech_for_prod",
        ),
        re_path(
            r"^technology/(?P<tid>\d+)/edit$",
            views.edit_technology,
            name="edit_technology",
        ),
        re_path(
            r"^technology/(?P<tid>\d+)/delete$",
            views.delete_technology,
            name="delete_technology",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/new_engagement/cicd$",
            views.new_eng_for_app_cicd,
            name="new_eng_for_prod_cicd",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/add_meta_data$",
            views.add_meta_data,
            name="add_meta_data",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/edit_notifications$",
            views.edit_notifications,
            name="edit_notifications",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/edit_meta_data$",
            views.edit_meta_data,
            name="edit_meta_data",
        ),
        re_path(
            r"^asset/(?P<product_id>\d+)/ad_hoc_finding$",
            views.AdHocFindingView.as_view(),
            name="ad_hoc_finding",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/engagement_presets$",
            views.engagement_presets,
            name="engagement_presets",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/engagement_presets/(?P<eid>\d+)/edit$",
            views.edit_engagement_presets,
            name="edit_engagement_presets",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/engagement_presets/add$",
            views.add_engagement_presets,
            name="add_engagement_presets",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/engagement_presets/(?P<eid>\d+)/delete$",
            views.delete_engagement_presets,
            name="delete_engagement_presets",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/add_member$",
            views.add_product_member,
            name="add_product_member",
        ),
        re_path(
            r"^asset/member/(?P<memberid>\d+)/edit$",
            views.edit_product_member,
            name="edit_product_member",
        ),
        re_path(
            r"^asset/member/(?P<memberid>\d+)/delete$",
            views.delete_product_member,
            name="delete_product_member",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/add_api_scan_configuration$",
            views.add_api_scan_configuration,
            name="add_api_scan_configuration",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/view_api_scan_configurations$",
            views.view_api_scan_configurations,
            name="view_api_scan_configurations",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/edit_api_scan_configuration/(?P<pascid>\d+)$",
            views.edit_api_scan_configuration,
            name="edit_api_scan_configuration",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/delete_api_scan_configuration/(?P<pascid>\d+)$",
            views.delete_api_scan_configuration,
            name="delete_api_scan_configuration",
        ),
        re_path(
            r"^asset/(?P<pid>\d+)/add_group$",
            views.add_product_group,
            name="add_product_group",
        ),
        re_path(
            r"^asset/group/(?P<groupid>\d+)/edit$",
            views.edit_product_group,
            name="edit_product_group",
        ),
        re_path(
            r"^asset/group/(?P<groupid>\d+)/delete$",
            views.delete_product_group,
            name="delete_product_group",
        ),
        # TODO: Backwards compatibility; remove after v3 migration is complete
        re_path(r"^product$", redirect_view("product")),
        re_path(r"^product/(?P<pid>\d+)$", redirect_view("view_product")),
        re_path(r"^product/(?P<pid>\d+)/components$", redirect_view("view_product_components")),
        re_path(r"^product/(?P<pid>\d+)/engagements$", redirect_view("view_engagements")),
        re_path(r"^product/(?P<product_id>\d+)/import_scan_results$", redirect_view("import_scan_results_prod")),
        re_path(r"^product/(?P<pid>\d+)/metrics$", redirect_view("view_product_metrics")),
        re_path(r"^product/(?P<pid>\d+)/async_burndown_metrics$", redirect_view("async_burndown_metrics")),
        re_path(r"^product/(?P<pid>\d+)/edit$", redirect_view("edit_product")),
        re_path(r"^product/(?P<pid>\d+)/delete$", redirect_view("delete_product")),
        re_path(r"^product/add", redirect_view("new_product")),
        re_path(r"^product/(?P<pid>\d+)/new_engagement$", redirect_view("new_eng_for_prod")),
        re_path(r"^product/(?P<pid>\d+)/new_technology$", redirect_view("new_tech_for_prod")),
        re_path(r"^product/(?P<pid>\d+)/new_engagement/cicd$", redirect_view("new_eng_for_prod_cicd")),
        re_path(r"^product/(?P<pid>\d+)/add_meta_data$", redirect_view("add_meta_data")),
        re_path(r"^product/(?P<pid>\d+)/edit_notifications$", redirect_view("edit_notifications")),
        re_path(r"^product/(?P<pid>\d+)/edit_meta_data$", redirect_view("edit_meta_data")),
        re_path(r"^product/(?P<product_id>\d+)/ad_hoc_finding$", redirect_view("ad_hoc_finding")),
        re_path(r"^product/(?P<pid>\d+)/engagement_presets$", redirect_view("engagement_presets")),
        re_path(r"^product/(?P<pid>\d+)/engagement_presets/(?P<eid>\d+)/edit$", redirect_view("edit_engagement_presets")),
        re_path(r"^product/(?P<pid>\d+)/engagement_presets/add$", redirect_view("add_engagement_presets")),
        re_path(r"^product/(?P<pid>\d+)/engagement_presets/(?P<eid>\d+)/delete$", redirect_view("delete_engagement_presets")),
        re_path(r"^product/(?P<pid>\d+)/add_member$", redirect_view("add_product_member")),
        re_path(r"^product/member/(?P<memberid>\d+)/edit$", redirect_view("edit_product_member")),
        re_path(r"^product/member/(?P<memberid>\d+)/delete$", redirect_view("delete_product_member")),
        re_path(r"^product/(?P<pid>\d+)/add_api_scan_configuration$", redirect_view("add_api_scan_configuration")),
        re_path(r"^product/(?P<pid>\d+)/view_api_scan_configurations$", redirect_view("view_api_scan_configurations")),
        re_path(r"^product/(?P<pid>\d+)/edit_api_scan_configuration/(?P<pascid>\d+)$", redirect_view("edit_api_scan_configuration")),
        re_path(r"^product/(?P<pid>\d+)/delete_api_scan_configuration/(?P<pascid>\d+)$", redirect_view("delete_api_scan_configuration")),
        re_path(r"^product/(?P<pid>\d+)/add_group$", redirect_view("add_product_group")),
        re_path(r"^product/group/(?P<groupid>\d+)/edit$", redirect_view("edit_product_group")),
        re_path(r"^product/group/(?P<groupid>\d+)/delete$", redirect_view("delete_product_group")),
    ]
else:
    urlpatterns = [
        #  product
        re_path(r"^product$", views.product, name="product"),
        re_path(r"^product/(?P<pid>\d+)$", views.view_product,
                name="view_product"),
        re_path(r"^product/(?P<pid>\d+)/components$", views.view_product_components,
                name="view_product_components"),
        re_path(r"^product/(?P<pid>\d+)/engagements$", views.view_engagements,
                name="view_engagements"),
        re_path(
            r"^product/(?P<product_id>\d+)/import_scan_results$",
            dojo_engagement_views.ImportScanResultsView.as_view(),
            name="import_scan_results_prod"),
        re_path(r"^product/(?P<pid>\d+)/metrics$", views.view_product_metrics,
                name="view_product_metrics"),
        re_path(r"^product/(?P<pid>\d+)/async_burndown_metrics$", views.async_burndown_metrics,
                name="async_burndown_metrics"),
        re_path(r"^product/(?P<pid>\d+)/edit$", views.edit_product,
                name="edit_product"),
        re_path(r"^product/(?P<pid>\d+)/delete$", views.delete_product,
                name="delete_product"),
        re_path(r"^product/add", views.new_product, name="new_product"),
        re_path(r"^product/(?P<pid>\d+)/new_engagement$", views.new_eng_for_app,
                name="new_eng_for_prod"),
        re_path(r"^product/(?P<pid>\d+)/new_technology$", views.new_tech_for_prod,
                name="new_tech_for_prod"),
        re_path(r"^technology/(?P<tid>\d+)/edit$", views.edit_technology,
                name="edit_technology"),
        re_path(r"^technology/(?P<tid>\d+)/delete$", views.delete_technology,
                name="delete_technology"),
        re_path(r"^product/(?P<pid>\d+)/new_engagement/cicd$", views.new_eng_for_app_cicd,
                name="new_eng_for_prod_cicd"),
        re_path(r"^product/(?P<pid>\d+)/add_meta_data$", views.add_meta_data,
                name="add_meta_data"),
        re_path(r"^product/(?P<pid>\d+)/edit_notifications$", views.edit_notifications,
                name="edit_notifications"),
        re_path(r"^product/(?P<pid>\d+)/edit_meta_data$", views.edit_meta_data,
                name="edit_meta_data"),
        re_path(
            r"^product/(?P<product_id>\d+)/ad_hoc_finding$",
            views.AdHocFindingView.as_view(),
            name="ad_hoc_finding"),
        re_path(r"^product/(?P<pid>\d+)/engagement_presets$", views.engagement_presets,
                name="engagement_presets"),
        re_path(r"^product/(?P<pid>\d+)/engagement_presets/(?P<eid>\d+)/edit$", views.edit_engagement_presets,
                name="edit_engagement_presets"),
        re_path(r"^product/(?P<pid>\d+)/engagement_presets/add$", views.add_engagement_presets,
                name="add_engagement_presets"),
        re_path(r"^product/(?P<pid>\d+)/engagement_presets/(?P<eid>\d+)/delete$", views.delete_engagement_presets,
                name="delete_engagement_presets"),
        re_path(r"^product/(?P<pid>\d+)/add_member$", views.add_product_member,
                name="add_product_member"),
        re_path(r"^product/member/(?P<memberid>\d+)/edit$", views.edit_product_member,
                name="edit_product_member"),
        re_path(r"^product/member/(?P<memberid>\d+)/delete$", views.delete_product_member,
                name="delete_product_member"),
        re_path(r"^product/(?P<pid>\d+)/add_api_scan_configuration$", views.add_api_scan_configuration,
                name="add_api_scan_configuration"),
        re_path(r"^product/(?P<pid>\d+)/view_api_scan_configurations$", views.view_api_scan_configurations,
                name="view_api_scan_configurations"),
        re_path(r"^product/(?P<pid>\d+)/edit_api_scan_configuration/(?P<pascid>\d+)$",
                views.edit_api_scan_configuration,
                name="edit_api_scan_configuration"),
        re_path(r"^product/(?P<pid>\d+)/delete_api_scan_configuration/(?P<pascid>\d+)$",
                views.delete_api_scan_configuration,
                name="delete_api_scan_configuration"),
        re_path(r"^product/(?P<pid>\d+)/add_group$", views.add_product_group,
                name="add_product_group"),
        re_path(r"^product/group/(?P<groupid>\d+)/edit$", views.edit_product_group,
                name="edit_product_group"),
        re_path(r"^product/group/(?P<groupid>\d+)/delete$", views.delete_product_group,
                name="delete_product_group"),
        # Forward compatibility
        re_path(r"^asset$", redirect_view("product")),
        re_path(r"^asset/(?P<pid>\d+)$", redirect_view("view_product")),
        re_path(r"^asset/(?P<pid>\d+)/components$", redirect_view("view_product_components")),
        re_path(r"^asset/(?P<pid>\d+)/engagements$", redirect_view("view_engagements")),
        re_path(r"^asset/(?P<product_id>\d+)/import_scan_results$", redirect_view("import_scan_results_prod")),
        re_path(r"^asset/(?P<pid>\d+)/metrics$", redirect_view("view_product_metrics")),
        re_path(r"^asset/(?P<pid>\d+)/async_burndown_metrics$", redirect_view("async_burndown_metrics")),
        re_path(r"^asset/(?P<pid>\d+)/edit$", redirect_view("edit_product")),
        re_path(r"^asset/(?P<pid>\d+)/delete$", redirect_view("delete_product")),
        re_path(r"^asset/add", redirect_view("new_product")),
        re_path(r"^asset/(?P<pid>\d+)/new_engagement$", redirect_view("new_eng_for_prod")),
        re_path(r"^asset/(?P<pid>\d+)/new_technology$", redirect_view("new_tech_for_prod")),
        re_path(r"^asset/(?P<pid>\d+)/new_engagement/cicd$", redirect_view("new_eng_for_prod_cicd")),
        re_path(r"^asset/(?P<pid>\d+)/add_meta_data$", redirect_view("add_meta_data")),
        re_path(r"^asset/(?P<pid>\d+)/edit_notifications$", redirect_view("edit_notifications")),
        re_path(r"^asset/(?P<pid>\d+)/edit_meta_data$", redirect_view("edit_meta_data")),
        re_path(r"^asset/(?P<product_id>\d+)/ad_hoc_finding$", redirect_view("ad_hoc_finding")),
        re_path(r"^asset/(?P<pid>\d+)/engagement_presets$", redirect_view("engagement_presets")),
        re_path(r"^asset/(?P<pid>\d+)/engagement_presets/(?P<eid>\d+)/edit$", redirect_view("edit_engagement_presets")),
        re_path(r"^asset/(?P<pid>\d+)/engagement_presets/add$", redirect_view("add_engagement_presets")),
        re_path(r"^asset/(?P<pid>\d+)/engagement_presets/(?P<eid>\d+)/delete$",
                redirect_view("delete_engagement_presets")),
        re_path(r"^asset/(?P<pid>\d+)/add_member$", redirect_view("add_product_member")),
        re_path(r"^asset/member/(?P<memberid>\d+)/edit$", redirect_view("edit_product_member")),
        re_path(r"^asset/member/(?P<memberid>\d+)/delete$", redirect_view("delete_product_member")),
        re_path(r"^asset/(?P<pid>\d+)/add_api_scan_configuration$", redirect_view("add_api_scan_configuration")),
        re_path(r"^asset/(?P<pid>\d+)/view_api_scan_configurations$", redirect_view("view_api_scan_configurations")),
        re_path(r"^asset/(?P<pid>\d+)/edit_api_scan_configuration/(?P<pascid>\d+)$",
                redirect_view("edit_api_scan_configuration")),
        re_path(r"^asset/(?P<pid>\d+)/delete_api_scan_configuration/(?P<pascid>\d+)$",
                redirect_view("delete_api_scan_configuration")),
        re_path(r"^asset/(?P<pid>\d+)/add_group$", redirect_view("add_product_group")),
        re_path(r"^asset/group/(?P<groupid>\d+)/edit$", redirect_view("edit_product_group")),
        re_path(r"^asset/group/(?P<groupid>\d+)/delete$", redirect_view("delete_product_group")),
    ]
